//
//  HRLikeMeTableViewCell.m
//  SpeedDating
//
//  Created by ISU1 on 17/1/4.
//  Copyright © 2017年 isu. All rights reserved.
//

#import "HRLikeMeTableViewCell.h"

@interface HRLikeMeTableViewCell ()

/**
 头像
 */
@property (nonatomic, strong) UIImageView *headImageView;
/**
 姓名
 */
@property (nonatomic, strong) UILabel *nickNameLabel;

@property (nonatomic, strong) UILabel *locationLabel;

@property (nonatomic, strong) UIView *giftView;

@property (nonatomic, strong) UIImageView *giftImageView;

@property (nonatomic, strong) UILabel *giftLabel;

@property (nonatomic, strong) UILabel *noteLabel;
/**
 来自哪里
 */
@property (nonatomic, strong) UILabel * WheredoesLab;
/**
 礼物图
 */
@property (nonatomic, strong) UIImageView *giftImgView;

/**
 索引
 */
@property (nonatomic, strong) NSIndexPath *indexPath;



@end

@implementation HRLikeMeTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath {
    static NSString *HRLikeMeTableViewCellIdent = @"HRLikeMeTableViewCellIdent";
    HRLikeMeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HRLikeMeTableViewCellIdent];
    if (!cell) {
        cell = [[HRLikeMeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:HRLikeMeTableViewCellIdent];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.indexPath = indexPath;
    
    return cell;

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _headImageView = [[UIImageView alloc] init];
        _headImageView.layer.cornerRadius = 25;
        _headImageView.layer.masksToBounds = YES;
        _headImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_headImageView];
        [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.top.equalTo(self).offset(15);
            make.height.width.mas_equalTo(50);
        }];
        _headImageButton = [UIButton new];
        [self.contentView addSubview:_headImageButton];
        [_headImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(_headImageView);
        }];
        _nickNameLabel = [[UILabel alloc] init];
        [self addSubview:_nickNameLabel];
        [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headImageView).offset(3);
            make.left.equalTo(_headImageView.mas_right).offset(10);
            make.width.mas_equalTo(180);
        }];
        
        _WheredoesLab = [[UILabel alloc]init];
        
        [self addSubview:_WheredoesLab];
        [_WheredoesLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_nickNameLabel.mas_bottom).offset(10);
            make.left.equalTo(_headImageView.mas_right).offset(10);
            make.width.mas_equalTo(180);
        }];
        
 
//        _locationLabel = [[UILabel alloc] init];
//        _locationLabel.textColor = [UIColor lightGrayColor];
//        _locationLabel.font = [UIFont systemFontOfSize:14];
//        [self addSubview:_locationLabel];
//        [_locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_nickNameLabel);
//            make.bottom.equalTo(_headImageView).offset(-3);
//            make.width.mas_equalTo(200);
//        }];
        _likeButton = [[UIButton alloc] init];
        [_likeButton setBackgroundImage:[UIImage imageNamed:@"news_likes"] forState:UIControlStateNormal];
        [self addSubview:_likeButton];
        [_likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-15);
            make.height.width.mas_equalTo(40);
            make.centerY.equalTo(_headImageView);
        }];
        _refuseButton = [[UIButton alloc] init];
        [_refuseButton setBackgroundImage:[UIImage imageNamed:@"news_dislike"] forState:UIControlStateNormal];
        [self addSubview:_refuseButton];
        [_refuseButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_likeButton.mas_left).offset(-10);
            make.top.bottom.width.equalTo(_likeButton);
        }];
        
        
        
        _giftImgView = [[UIImageView alloc]init];
        _giftImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_giftImgView];
        [_giftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-55);
            make.width.height.mas_equalTo(40);
            make.centerY.equalTo(_headImageView);
            
        }];
        _giftImgView.hidden = YES;
        
        
        
        
        
        UILabel *linView = [[UILabel alloc] init];
        linView.backgroundColor = RGB(246, 246, 246);
        [self addSubview:linView];
        [linView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.left.equalTo(self);
            make.bottom.equalTo(self.mas_bottom);
            make.height.mas_equalTo(1);
        }];
        
        
        
////        _giftView = [[UIView alloc] init];
////        _giftView.backgroundColor = RGB(244, 244, 244);
////        [self addSubview:_giftView];
////        [_giftView mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.left.equalTo(_nickNameLabel);
////            make.right.equalTo(_likeButton);
////            make.top.equalTo(_headImageView.mas_bottom).offset(15);
////            make.height.mas_equalTo(80);
////        }];
////        _giftImageView = [[UIImageView alloc] init];
////        [_giftView addSubview:_giftImageView];
////        [_giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.centerY.equalTo(_giftView);
////            make.left.equalTo(_giftView).offset(10);
////            make.height.width.mas_equalTo(60);
////        }];
////        _giftLabel = [[UILabel alloc] init];
////        _giftLabel.textColor = [UIColor lightGrayColor];
////        _giftLabel.font = [UIFont systemFontOfSize:13];
////        [_giftView addSubview:_giftLabel];
////        [_giftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.left.equalTo(_giftImageView.mas_right).offset(10);
////            make.right.equalTo(_giftView).offset(-10);
////            make.top.equalTo(_giftImageView).offset(10);
////        }];
////        _noteLabel = [[UILabel alloc] init];
////        _noteLabel.textColor = [UIColor lightGrayColor];
////        _noteLabel.font = [UIFont systemFontOfSize:13];
////        [_giftView addSubview:_noteLabel];
////        [_noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.left.equalTo(_giftImageView.mas_right).offset(10);
////            make.right.equalTo(_giftView).offset(-10);
////            make.bottom.equalTo(_giftImageView).offset(-10);
////        }];
//        _giftView.layer.cornerRadius = 5;
//        _giftView.layer.masksToBounds = YES;
//        _giftView.hidden = YES;
    }
    return self;
}

+ (CGFloat)getHeightWithModel:(HRLikeMeModel *)model {
//    if (model.img.length) {
//        return 80+95;
//    }
    return 80.0f;
}

- (void)setModel:(HRLikeMeModel *)model {
    if(model.photo){
       [_headImageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(model.photo)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    }
    if(model.nickName){
        _nickNameLabel.text = model.nickName;
    }
    
    if (model.where == 0) {
        _WheredoesLab.text = [NSString stringWithFormat:@"她是你附近的人"];
    }else{
        _WheredoesLab.text = [NSString stringWithFormat:@"TA曾与你视过频"];

    }
   
    
    if (model.img.length>0) {
        _likeButton.hidden = YES;
        _refuseButton.hidden = YES;
        [_giftImgView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(model.img)] placeholderImage:[UIImage imageNamed:@"llustration"]];
        _giftImgView.hidden = NO;
    }else{
        _likeButton.hidden = NO;
        _refuseButton.hidden = NO;
        _giftImgView.hidden = YES;
    }

    
    
    
    
    
    
    
    
    
    
    
//    _locationLabel.text = [model.location stringByAppendingString:[NSString stringWithFormat:@" %0.1fkm",model.distance/1000.0f]];
//    if (model.img.length) {
//        _giftView.hidden = NO;
//        [_giftImageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(model.img)]];
//        _giftLabel.text = [NSString stringWithFormat:@"对方送你个%@ 价值：%ld钻石",model.giftName,(long)model.charm];
//        _noteLabel.text = [NSString stringWithFormat:@"对方留言：%@",model.msg.length?model.msg:@"无"];
//    }
}

@end
